package com.px.plan.controller;

import com.px.common.annotation.Log;
import com.px.common.core.controller.BaseController;
import com.px.common.core.domain.AjaxResult;
import com.px.common.core.page.TableDataInfo;
import com.px.common.enums.BusinessType;
import com.px.common.utils.poi.ExcelUtil;
import com.px.framework.aes.AesSecurityParameter;
import com.px.plan.domain.PlanActionRecord;
import com.px.plan.service.IPlanActionRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 飞行行动记录Controller
 * 
 * @author WRJ
 * @date 2024-08
 */
@Api("飞行记录管理")
@RestController
@RequestMapping("/plan/record")
public class PlanActionRecordController extends BaseController
{
    @Autowired
    private IPlanActionRecordService planActionRecordService;

    /**
     * 飞行记录列表
     */
    @ApiOperation("飞行记录列表")
    @PreAuthorize("@ss.hasPermi('plan:record:query')")
    @GetMapping("/list")
    @AesSecurityParameter(outEncode = true)
    public TableDataInfo list(PlanActionRecord planActionRecord)
    {
        startPage();
        List<PlanActionRecord> list = planActionRecordService.selectPlanActionRecordList(planActionRecord);
        return getDataTable(list);
    }

    /**
     * 导出飞行行动记录列表
     */
    @ApiOperation("导出飞行记录列表")
    @PreAuthorize("@ss.hasPermi('plan:record:query')")
    @Log(title = "导出飞行记录列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @AesSecurityParameter
    public void export(HttpServletResponse response, PlanActionRecord planActionRecord)
    {
        List<PlanActionRecord> list = planActionRecordService.selectPlanActionRecordList(planActionRecord);
        ExcelUtil<PlanActionRecord> util = new ExcelUtil<PlanActionRecord>(PlanActionRecord.class);
        util.exportExcel(response, list, "飞行记录列表");
    }

    /**
     * 飞行记录详情
     */
    @ApiOperation("飞行记录详情")
    @PreAuthorize("@ss.hasPermi('plan:record:query')")
    @GetMapping(value = "/{id}")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(planActionRecordService.selectPlanActionRecordById(id));
    }

    /**
     * 新增飞行记录
     */
    @ApiOperation("新增飞行记录")
    @PreAuthorize("@ss.hasPermi('plan:record:edit')")
    @Log(title = "新增飞行记录", businessType = BusinessType.INSERT)
    @PostMapping
    @AesSecurityParameter(outEncode = true)
    public AjaxResult add(@RequestBody PlanActionRecord planActionRecord)
    {
        return toAjax(planActionRecordService.insertPlanActionRecord(planActionRecord));
    }

    /**
     * 修改飞行记录
     */
    @ApiOperation("修改飞行记录")
    @PreAuthorize("@ss.hasPermi('plan:record:edit')")
    @Log(title = "修改飞行记录", businessType = BusinessType.UPDATE)
    @PutMapping
    @AesSecurityParameter(outEncode = true)
    public AjaxResult edit(@RequestBody PlanActionRecord planActionRecord)
    {
        return toAjax(planActionRecordService.updatePlanActionRecord(planActionRecord));
    }

    /**
     * 删除飞行记录
     */
    @ApiOperation("删除飞行记录")
    @PreAuthorize("@ss.hasPermi('plan:record:remove')")
    @Log(title = "删除飞行记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult remove(@PathVariable Long[] ids) throws Exception {
        return toAjax(planActionRecordService.deletePlanActionRecordByIds(ids));
    }
}
